home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
intset2.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
898b
|
45 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
ifdef NONLOCAL /* DELETE */
include <intset.h>
else /* DELETE */
include "intset.h" /* DELETE */
endif /* DELETE */
/ remove a member from an intset
oid intset::remove(int t)
// look for the member
// using a binary search,
// just as was done in
// intset::member()
int l = 0;
int u = cursize - 1;
while (l <= u)
{
int m = (l+u) / 2;
if (t < x[m]) u = m - 1;
else if (t > x[m]) l = m + 1;
else // found it, shift the remaining
{ // elements to the left
for (int n = m + 1; n < cursize; n++, m++)
x[m] = x[n];
cursize--;
return;
}
}
// not found, do nothing